package com.breeze.algorithm.sort;

import java.util.Arrays;

/**
 * 插入排序
 * @author yangzh
 * @date 2025/5/21
 */
public class InsertionSort {

    public static void main(String[] args) {
        int[] numbs = {2, 2, 4, 3, 7, 5, 1};
        InsertionSort.insertionSort(numbs);
        System.out.println(Arrays.toString(numbs));
    }

    public static void insertionSort(int[] numbs) {
        int cursor = 1, temp;
        while (cursor < numbs.length) {
            for (int i = cursor; i > 0; i--) {
                if (numbs[i] < numbs[i - 1]) {
                    temp = numbs[i];
                    numbs[i] = numbs[i - 1];
                    numbs[i - 1] = temp;
                } else {
                    break;
                }
            }
            cursor++;
        }
    }
}
